<script lang="ts" setup>
import { reactive, defineEmits } from "vue"
import { useRouter } from 'vue-router'
import { addPersonalChannel } from '../../../../api/personalChannel'
import { HttpStatusCode } from "axios"
import { ElMessage } from "element-plus"
import { usingNature, energyNature } from '../../../../enums/PersonalChannel'

const router = useRouter()
const emits = defineEmits(['increase', 'closeShow'])
let formLabelAlign = reactive<PersonalChannel>({
  //车源名称
  personalCarName: '',
  brand: '',
  //指导价
  personalCarPrice: 0,
  //表显里程
  mileage: 0,
  //初次上牌日
  registrationDate: '',
  //车辆归属地
  homeLocation: '',
  //排放标准
  emissionStandard: '',
  //能源种类
  energy: null,
  //保险到期日
  insuranceDate: '',
  //排量/变速箱
  gearbox: '',
  //年检到期日
  annualInspection: '',
  //车辆所在地
  location: '',
  //使用性质
  usingNature: null,
  //联系电话
  phone: '',
  //车辆描述
  description: '',
  useCoin: 0,
})

const submitData = async () => {
  const res = await addPersonalChannel(formLabelAlign)
  if(res.statusCode === HttpStatusCode.Created) {
    ElMessage({
      message: '添加成功',
      type: 'success',
    })
    emits('increase', 1, '')
    emits('closeShow')
  } else {
    ElMessage({
      message: '添加失败',
      type: 'error',
    })
  }
}
</script>

<template>
  <el-form
      label-position="top"
      label-width="100px"
      :model="formLabelAlign"
      style="max-width: 460px"
  >
    <el-form-item label="车源名称">
      <el-input v-model="formLabelAlign.personalCarName" />
    </el-form-item>
    <el-form-item label="品牌">
      <el-input v-model="formLabelAlign.brand" />
    </el-form-item>
    <el-form-item label="指导价(万)">
      <el-input-number v-model="formLabelAlign.personalCarPrice" :precision="1" :step="0.1">
      </el-input-number>
    </el-form-item>
    <el-form-item label="表显里程(万公里)">
      <el-input-number v-model="formLabelAlign.mileage" :precision="1" :step="0.1">
      </el-input-number>
    </el-form-item>
    <el-form-item label="上牌日期">
      <el-date-picker
          v-model="formLabelAlign.registrationDate"
          type="date"
          placeholder="选择日期"
          value-format="YYYY-MM-DD"
          size="default"
      />
    </el-form-item>
    <el-form-item label="车辆归属地">
      <el-input v-model="formLabelAlign.homeLocation" />
    </el-form-item>
    <el-form-item label="车辆所在地">
      <el-input v-model="formLabelAlign.location" />
    </el-form-item>
    <el-form-item label="能源种类">
      <el-select v-model="formLabelAlign.energy" placeholder="选择能源种类">
        <el-option
            v-for="item in energyNature"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="排放标准">
      <el-input v-model="formLabelAlign.emissionStandard" :disabled="formLabelAlign.energy === 2" />
    </el-form-item>
    <el-form-item label="保险到期日">
      <el-date-picker
          v-model="formLabelAlign.insuranceDate"
          type="date"
          placeholder="选择日期"
          value-format="YYYY-MM-DD"
          size="default"
      />
    </el-form-item>
    <el-form-item label="排量/变速箱">
      <el-input v-model="formLabelAlign.gearbox" :disabled="formLabelAlign.energy === 2" />
    </el-form-item>
    <el-form-item label="年检到期日">
      <el-date-picker
          v-model="formLabelAlign.annualInspection"
          type="date"
          placeholder="选择日期"
          value-format="YYYY-MM-DD"
          size="default"
      />
    </el-form-item>
    <el-form-item label="使用性质">
      <el-select v-model="formLabelAlign.usingNature" placeholder="选择使用性质">
        <el-option
            v-for="item in usingNature"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="联系电话">
      <el-input v-model="formLabelAlign.phone" />
    </el-form-item>
    <el-form-item label="车辆描述">
      <el-input :rows="2" type="textarea" v-model="formLabelAlign.description" />
    </el-form-item>
    <el-form-item label="所需积分">
      <el-input-number v-model="formLabelAlign.useCoin">
      </el-input-number>
    </el-form-item>
  </el-form>
  <el-button type="primary" @click="submitData">提交</el-button>
</template>

<style lang="less" scoped>
</style>